﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Drawing;
using DevExpress.Web.ASPxGridView;

public partial class _Default : System.Web.UI.Page
{
    //public DateTime _StartDate { get { return DateTime.Parse(ViewState["startdate"].ToString()); } set { ViewState["startdate"] = value; } }
    //public DateTime _EndDate { get { return DateTime.Parse(ViewState["enddate"].ToString()); } set { ViewState["enddate"] = value; } }

    protected void Page_Load(object sender, EventArgs e)
    {
        System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-CHS");
        DevExpress.Web.ASPxClasses.Localization.ASPxperienceLocalizer.Active = new DevExpress.LocalizationCHS.DevExpressWebASPxClassesLocalizationCHS();
        DevExpress.Web.ASPxEditors.Localization.ASPxEditorsLocalizer.Active = new DevExpress.LocalizationCHS.DevExpressWebASPxEditorsLocalizationCHS();
        DevExpress.Web.ASPxGridView.Localization.ASPxGridViewLocalizer.Active = new DevExpress.LocalizationCHS.DevExpressWebASPxGridViewLocalizationCHS();

        if (!IsPostBack)
        {

            //DevExpress.Web.ASPxHtmlEditor.Localization.ASPxHtmlEditorLocalizer.Active = new DevExpress.LocalizationCHS.DevExpressWebASPxHtmlEditorLocalizationCHS();
            //DevExpress.Web.ASPxScheduler.Localization.ASPxSchedulerLocalizer.Active = new DevExpress.LocalizationCHS.DevExpressWebASPxSchedulerLocalizationCHS();
            //DevExpress.Web.ASPxSpellChecker.Localization.ASPxSpellCheckerLocalizer.Active = new DevExpress.LocalizationCHS.DevExpressWebASPxSpellCheckerLocalizationCHS();
            //DevExpress.Web.ASPxTreeList.Localization.ASPxTreeListLocalizer.Active = new DevExpress.LocalizationCHS.DevExpressWebASPxTreeListLocalizationCHS();

            //默认为上月1日起，下下月1日止
            dateStart.Value = DateTime.Parse(string.Format("{0}-{1}-01", DateTime.Now.Month > 1 ? DateTime.Now.Year : DateTime.Now.Year - 1, DateTime.Now.Month > 1 ? DateTime.Now.Month - 1 : 12));
            dateEnd.Value = DateTime.Parse(string.Format("{0}-{1}-01", DateTime.Now.Year + DateTime.Now.Month / 11, (DateTime.Now.Month + 1) % 12 + 1));
        }
        if (IsPostBack)
        {
            if(Request.Params["type"]==null) return;

            switch (Request.Params["type"].ToString())
            {
                case "0":
                    GridViewNormalDataBind();
                    break;
                case "1":
                    GetViewGuestSearchData();
                    break;
                default:
                    break;
            }
        }
    }
    private void GetViewGuestSearchData()
    {
        string guestName = guestSearch.Value == null ? "" : guestSearch.Value.ToString();
        teamGridView.DataSource = TeamGroupCtrl.GetTeamGroupData(guestName);
        teamGridView.DataBind();
    }
    private void GridViewNormalDataBind()
    {
        TeamStateEnum teamState = comboStatus.SelectedItem.Value == null ? TeamStateEnum.全部 : EnumHelper.Team_Str2Enum(comboStatus.SelectedItem.Value.ToString(), true);
        DateTime dateStart = DateTime.Parse(this.dateStart.Value.ToString());
        DateTime dateEnd = DateTime.Parse(this.dateEnd.Value.ToString());

        teamGridView.DataSource = TeamGroupCtrl.GetTeamGroupData(dateStart, dateEnd, teamState, tbToursName.Text);//根据选择的部门过滤
        teamGridView.DataBind();
    }
    protected void teamGridView_HtmlRowPrepared(object sender, ASPxGridViewTableRowEventArgs e)
    {

        object state = teamGridView.GetRowValuesByKeyValue(e.KeyValue, "TourgroupRowState");

        if (state == null) return;

        switch (state.ToString())
        {
            case "0"://预留
            case "1"://预留
                break;
            case "2"://此团为已经操作过（手工在计划中设置的）
                e.Row.BackColor = Color.Cyan;
                break;
            default:
                break;
        }
    }

    protected void teamGridView_SelectionChanged(object sender, EventArgs e)
    {
        //DataRowView dv;
        //for (int i = 0; i < teamGridView.VisibleRowCount; i++)
        //{
        //    if(teamGridView.Selection.IsRowSelected(i))
        //    {
        //        dv = (DataRowView)teamGridView.GetRow(i);
        //    }
        //}
        
    }
}
